package com.dyp.modulith_demo.model2d.listener;


import com.dyp.modulith_demo.model2d.api.model.SampleInfoEventDTO;
import com.dyp.modulith_demo.model2d.event.SampleInfoEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 这里的实现可以在分服务后，切换成MQ的消息费者
 */
@Component("ServiceBApiListener2")
public class ServiceBApiListener {
    @EventListener
    @Async  // 异步执行,不是非必须的，可以去掉，同时去掉ModulithDemoApplication中的@EnableAsync
    public void handleSampleInfoCreatedEvent(SampleInfoEventDTO sampleInfoEventDTO){
        SampleInfoEvent sampleInfoEvent = new SampleInfoEvent(sampleInfoEventDTO.sampleInfo());
        System.out.println(sampleInfoEvent.toString() + " 2");
    }
}
